<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 16] jar</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:04:06 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch16_01.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 16<br>JDK Tools</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch16_03.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<A NAME="CH16.JAR.ARCHIVES1"></A>

<DIV CLASS=refnamediv>
<H1>jar</H1>

<H2>Name</H2>

jar---Java Archive Tool

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JNUT2-CH-16-SECT-2.1">Availability</A></h2>

<P CLASS=para>
JDK 1.1 and later.

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JNUT2-CH-16-SECT-2.2">Synopsis</A></h2>

<DIV CLASS=screen>
<P>
<PRE>
jar c|t|x[f][m][v] [<I CLASS=emphasis>jar-file</I>] [<I CLASS=emphasis>manifest-file</I>] [<I CLASS=emphasis>files</I>]
</PRE>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JNUT2-CH-16-SECT-2.3">Description</A></h2>

<P CLASS=para>
<I CLASS=emphasis>jar</I> is a tool that can be used to create and manipulate
Java Archive (JAR) files.  A JAR file is a compressed ZIP
file with an additional "manifest" file.  The syntax of
the <I CLASS=emphasis>jar</I> command is reminiscent of the Unix <I CLASS=emphasis>tar</I>
(tape archive) command.

<P CLASS=para>
Options to <I CLASS=emphasis>jar</I> are specified as a block of
concatenated letters passed as a single
argument, rather than as individual command-line arguments.
The first letter of this option argument specifies
what action <I CLASS=emphasis>jar</I> is to perform and is required.
Other option letters are optional.  The various file
arguments depend on which option letters are specified.

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JNUT2-CH-16-SECT-2.4">Options</A></h2>

<P CLASS=para>
The first argument to <I CLASS=emphasis>jar</I> is a set of letters that
specifies the operation it is to perform.  The first letter
specifies the basic action and is required.  The three
possible values are the following:

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>c</tt><br>
<DD>

<P CLASS=para>
Create a new JAR archive.  A list of input files
and/or directories must be specified as the
final arguments to <I CLASS=emphasis>jar</I>.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>t</tt><br>
<DD>

<P CLASS=para>
List the contents of a JAR archive.  If a JAR file is
specified with the <tt CLASS=literal>f</tt> option, its contents are
listed.  Otherwise, the JAR file to be listed is read from
standard input.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>x</tt><br>
<DD>

<P CLASS=para>
Extract the contents of a JAR archive.  If a JAR file is
specified with the <tt CLASS=literal>f</tt> option, its contents are
extracted.  Otherwise, the JAR file to be extracted is
read from standard input.
If the command is followed by a list
of files and/or directories, only those files or directories
are extracted from the JAR archive.  Otherwise,
all files in the archive are extracted.

<P CLASS=para>
This action specifier can be followed by optional command letters:

<p>
<DT CLASS=varlistentry><tt CLASS=literal>f</tt><br>
<DD>

<P CLASS=para>
This option indicates that the JAR file to create,
list, or extract from is specified on the command line.
When <tt CLASS=literal>f</tt> is used with <tt CLASS=literal>c</tt>, <tt CLASS=literal>t</tt>, or
<tt CLASS=literal>x</tt>, the JAR filename must be the second command-line
argument to <I CLASS=emphasis>jar</I> (i.e., it must follow the block of option letters).
If this option is not specified, <I CLASS=emphasis>jar</I> writes the
JAR file it creates to standard output, or reads a JAR
file from standard input.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>m</tt><br>
<DD>

<P CLASS=para>
This option is only used with the <tt CLASS=literal>c</tt> action.  It
indicates that <I CLASS=emphasis>jar</I> should read the manifest file
(partial or complete) specified on the command line and use
that file as the basis for the manifest it includes in the
JAR file.  When this argument is specified after the
<tt CLASS=literal>f</tt> option, the manifest filename should follow the
destination filename.  If <tt CLASS=literal>m</tt> precedes the <tt CLASS=literal>f</tt>
option, the manifest filename should precede the
destination filename.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>v</tt><br>
<DD>

<P CLASS=para>
Verbose.  If this letter is specified with a <tt CLASS=literal>c</tt>
action, <I CLASS=emphasis>jar</I> lists each file it adds to the
archive with compression statistics.  If it is used with a
<tt CLASS=literal>t</tt> action, <I CLASS=emphasis>jar</I> lists the size
and modification date for each file in the archive, instead
of simply listing the filename.  If <tt CLASS=literal>v</tt> is used with
<tt CLASS=literal>x</tt>, <I CLASS=emphasis>jar</I> displays the name of each file it
extracts from the archive.</DL>
</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JNUT2-CH-16-SECT-2.5">Examples</A></h2>

<P CLASS=para>
To create a simple JAR file:

<DIV CLASS=screen>
<P>
<PRE>
% jar cvf my.jar *.java images
</PRE>
</DIV>

<P CLASS=para>
To list the contents of a file:

<DIV CLASS=screen>
<P>
<PRE>
% jar tvf your.jar
</PRE>
</DIV>

<P CLASS=para>
To extract the manifest file from a JAR file:

<DIV CLASS=screen>
<P>
<PRE>
% jar xf the.jar META-INF/MANIFEST.MF
</PRE>
</DIV>

<P CLASS=para>
To create a JAR file with a partial manifest specified:

<DIV CLASS=screen>
<P>
<PRE>
% jar cfmv YesNoDialog.jar manifest.stub oreilly/beans/yesno
</PRE>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JNUT2-CH-16-SECT-2.6">See Also</A></h2>

<P CLASS=para>
<I CLASS=emphasis>javakey</I>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch16_01.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch16_03.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>appletviewer</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>java</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
